package com.kun.service_train.listener;

import com.alibaba.excel.context.AnalysisContext;
import com.alibaba.excel.event.AnalysisEventListener;
import com.kun.service_train.entity.Student;
import com.kun.service_train.entity.excel.StudentData;
import com.kun.service_train.service.StudentService;
import com.kun.servicebase.exceptionhandler.KunException;

public class studentListener extends AnalysisEventListener<StudentData> {

    public StudentService subjectService;

    public studentListener(StudentService studentService) {
        this.subjectService= studentService;
    }
    @Override
    public void invoke(StudentData studentData, AnalysisContext analysisContext) {
        if (studentData == null) {
            throw new KunException(20001,"文件为空");
        }
        Student ExcelStudent = new Student();
        ExcelStudent.setAge(studentData.getAge());
        ExcelStudent.setClasses(studentData.getClasses());
        ExcelStudent.setGrade(studentData.getGrade());
        ExcelStudent.setSex(studentData.getSex());
        ExcelStudent.setStuName(studentData.getStuName());
        subjectService.save(ExcelStudent);
    }

    @Override
    public void doAfterAllAnalysed(AnalysisContext analysisContext) {

    }
}
